/*
 * @Author: QinJiu
 * @Date: 2022-06-09 16:51:41
 * @LastEditors: Qinjiu
 * @LastEditTime: 2022-07-20 09:49:33
 * @Description: 参考 https://github.com/scopsy/await-to-js
 */

/**
 * 异步等待包装器，便于错误处理
 * @param { Promise } 传进去的请求函数
 * @return { Promise } 返回一个Promise
 */
export default function awaitTo(promise) {
  return promise
    .then((result) => [null, result])
    .catch((error) => [error, undefined]);
}
